import * as vscode from 'vscode';
import { SnippetManager } from '../utils/snippetManager';

export class ExportSnippetsCommand {
    constructor(private snippetManager: SnippetManager) {}

    get commandId(): string {
        return 'snippetManager.exportSnippets';
    }

    async execute(): Promise<void> {
        try {
            const snippets = this.snippetManager.getAllSnippets();
            if (snippets.length === 0) {
                vscode.window.showInformationMessage('No snippets to export');
                return;
            }

            // 选择导出文件路径
            const uri = await vscode.window.showSaveDialog({
                defaultUri: vscode.Uri.file('snippets.json'),
                filters: {
                    'JSON Files': ['json'],
                    'All Files': ['*']
                }
            });

            if (!uri) return;

            // 导出代码片段
            await this.snippetManager.exportSnippets(uri.fsPath);
            vscode.window.showInformationMessage(`Snippets exported to ${uri.fsPath}`);

        } catch (error) {
            vscode.window.showErrorMessage(`Failed to export snippets: ${error}`);
        }
    }
}
